﻿#ifndef PROJECTFILEIO_H
#define PROJECTFILEIO_H

#include "API_ProjectManager.h"
#include "BaseModule/IOBase.h"
#include "BaseWidget/ThreadTask.h"

namespace ProjectManager
{
    class CaseModelManager;
}
namespace DataManager
{
    class WindowTotalData;
}

class QDomNodeList;

namespace ProjectManager
{
    enum class ProjectOperateType
    {
        None = 0,       //无
        Open = 1,       //1打开,
        Save = 2,       //2保存,
        Create = 3,     //3创建,
    };

    class API_PROJECTMANAGER ProjectFileIO : public BaseWidget::ThreadTask, public BaseModule::IOBase
    {
        Q_OBJECT
    public:
        ProjectFileIO(const QString& fileName, ProjectOperateType operateType = ProjectOperateType::Save);
        ~ProjectFileIO() = default;

        void run() override;

        void setSavePy(bool savePy) { m_savePy = savePy; }

        bool isFinished() { return m_execFinish; }


    signals:
        void processFinished(QString fileName, bool, int);

    private:
        bool read() override;
        bool write(QString fileName = QString()) override;
        bool create(QString fileName = QString());
    
        bool writeXml(QString fileName, bool isSave = true);
        bool writePPC(QString fileName, bool isSave = true);

        bool readXml(QString fileName);
        bool readPPC(QString fileName);

        bool readModelData(QDomNodeList* nodeList);

    private:
        QString m_tempIODir;
        DataManager::WindowTotalData* m_windowTotalData{};
        ProjectOperateType m_operateType{ ProjectOperateType::None };
        bool m_savePy = true;
    
    public:
        bool m_execFinish;

    };
}


#endif
